package com.hgc.controller;

import com.hgc.entity.User;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@RequestMapping("consumer")
public class ConsumerController {

    public final String FIND_USER_URL = "http://localhost:8080/user/find/";

    @Resource
    private RestTemplate restTemplate;

    @Resource
    private HttpHeaders httpHeaders;

    @RequestMapping("user/find/{id}")
    public User findUserById(@PathVariable Integer id){
        //User user = restTemplate.getForObject(FIND_USER_URL + id, User.class);
        User user = restTemplate.exchange(FIND_USER_URL + id, HttpMethod.GET, new HttpEntity<>(httpHeaders), User.class).getBody();
        return user;
    }

}
